#ifndef QFORMWIDGET_H
#define QFORMWIDGET_H

#include "../../libs/sharedLib/qpagewidget.h"

#include <QWidget>
#include <QVariant>

class WidgetHost;
class QRubberBand;
class Selection;

class QFormWidget : public SHAREDLIB::QPageWidget
{
    Q_OBJECT
public:
    explicit QFormWidget(const QString &type,QWidget *parent=0) ;
    ~QFormWidget();
    void setWidgetHost(WidgetHost *host);
    WidgetHost *widgetHost();
    void setName(const QString &name);
    void setDefaultValue();
    QString name();
    void load(const QString &data,const QString &type);

    void    left();
    void    h_center();
    void    right();
    void    top();
    void    v_center();
    void    bottom();

    void    sameWidth();
    void    sameHeight();
    void    sameGemotry();

    bool    isNull();

    QString get_ui_string();
    int     get_select_count();

    void    widget_mouse_release(QWidget* wid,const QRect& old,const QRect &now);

    void    make_page_position(QVariant &info);
    void    set_page_position(const QVariant &info);
    bool    page_position(const QVariant &info);
signals:
    void        select_changed();
public slots:
    void deleteSelectWidget();

    void        selectWidget(QWidget *wid);
    void        selectThis();
    void        clearSelect();
    void        copy();
    void        cut();
    void        paste();
    void        selectAll();

protected slots:
    void        size_changed(const QRect &,const QRect &);
    void        cammand_widget_add();
    void        cammand_widget_remove();
    void        cammand_widget_destory();
    void        cammand_property_redo();
    void        cammand_property_undo();
    void        cammand_widget_move_redo();
    void        cammand_widget_move_undo();
protected:
    bool eventFilter(QObject *, QEvent *);

    bool    handlePainteEvent(QWidget *wid, QPaintEvent *e);
    bool    handleMousePressEvent(QWidget* wid, QMouseEvent *e);
    bool    handleMouseMoveEvent(QWidget* wid, QMouseEvent *e);
    bool    handleMouseRelessEvent(QWidget* wid, QMouseEvent *e);
    bool    handleMouseDoubleEvent(QWidget* wid, QMouseEvent *e);
    void    handleContextMenuEvent(QWidget* wid, QContextMenuEvent *e);
protected:
    void paintEvent(QPaintEvent *e);
    void mousePressEvent(QMouseEvent *);
    void mouseMoveEvent(QMouseEvent *);
    void mouseReleaseEvent(QMouseEvent *);
    void keyPressEvent(QKeyEvent *);
    void resizeEvent(QResizeEvent *);
    void dropEvent(QDropEvent *);
    void dragEnterEvent(QDragEnterEvent *);
    void contextMenuEvent(QContextMenuEvent *);

signals:
    void    select(QWidget* wid);
    void    widgetAdd(QWidget* wid,int index);
    void    widgetRemove(QWidget* wid);
    void    need_make_page_position();
protected:
    QWidget*    addWidget(const QString &name, const QString &pluginName="");
    QWidget*    designerWidget(QWidget *widget);

    void        movePress(int type);
    void        moveSelect(int type);
protected:
    WidgetHost      *m_widgetHost;
    QString         m_name;
    QRubberBand     *m_rubber;
    QPoint          m_clickPoint;
    Selection       *m_selection;
    QList<QWidget*> m_widgets;
    bool            m_click;
    QVariant        m_page_position;
};

#endif // QFORMWIDGET_H
